<?php
include_once "checkAdmin.php";
?>
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>后台管理</title>
    <style>
        h1 {
            text-align: center;
            margin-bottom: 10px;
            line-height: 50px;
        }

        img {
            width: 100%;
            /*margin-bottom: 10px*/
        }

        .number {
            float: right;
            font-size: 14px;
            font-weight: normal;
        }

        h5 {
            line-height: 150%
        }

        .row {
            margin: 5px 10px
        }

        .row img {
            cursor: pointer
        }

        .uinfo {
            float: right;
            line-height: 80px;
            margin-right: 10px
        }

        .title {
            width: 80%;
            float: left;
            text-align: center;
        }

        .layui-btn {
            margin-top: 20px
        }
    </style>
</head>
<body>
<div style="margin-top: 45px">
    <h1 class="title">后台管理</h1>
    <div class="uinfo">
        <a href="singUp.html">注册</a>
        <a href="login.html">登录</a>
        <a href="admin.php">后台管理</a>
        <?php if (isset($_SESSION['logged']) && $_SESSION['logged'] == 1) { ?>
            <a href="logout.php">注销</a>
        <?php } ?>
    </div>
    <div class="clearfix"></div>
</div>
<table border="1" width="100%" bordercolor="black" style="border-collapse: collapse">
    <tr>
        <td align="center">序号</td>
        <td align="center">名称</td>
        <td align="center">介绍</td>
        <td align="center">图片</td>
        <td align="center">票数</td>
        <td align="center">操作</td>
    </tr>
    <?php
    include_once "conn.php";
    $sql = "select * from object order by id desc ";
    $result = mysqli_query($conn, $sql);
    $i = 1;
    while ($info = mysqli_fetch_array($result)) {
        ?>
        <tr>
            <td align="center" width="10%"><?php echo $i; ?></td>
            <td align="center" width="15%"><?php echo $info['name']; ?></td>
            <td align="center" width="30%"><?php echo $info['description']; ?></td>
            <td align="center" valign="center" width="20%"><img src="<?php echo $info['pic']; ?>" style="width: 80px">
            </td>
            <td align="center" width="10%"><?php echo $info['vote']; ?></td>
            <td align="center" width="15%"><a href="del.php?id=<?php echo $info['id']; ?>">删除</a> <a href="modify.php?id=<?php echo $info['id']; ?>"> 编辑</a></td>
        </tr>
        <?php
        $i++;
    }
    ?>
</table>
<h1 class="title">添加投票对象　　　　 <span><a href="charts.html">查看图表</a></span></h1>
<form action="postAddObject.php" method="post" enctype="multipart/form-data">
    <table cellpadding="15" border="1" width="100%" bordercolor="black" style="border-collapse: collapse">
        <tr>
            <td align="right">对象名称</td>
            <td><input name="name"></td>
        </tr>
        <tr>
            <td align="right">对象介绍</td>
            <td><textarea name="description"></textarea></td>
        </tr>
        <tr>
            <td align="right">对象图片</td>
            <td><input type="file" name="pic"><input type="hidden" name="MAX_FILE_SIZE" value="2000000"></td>
        </tr>
        <tr>
            <td align="right"><input type="submit" value="提交"></td>
            <td><input type="reset" value="重置"></td>
        </tr>
    </table>
</form>
</body>
</html>